<%@ page language="java" import="java.util.*,com.mongodb.*,org.bson.types.ObjectId" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>增加阅读量</title>
</head>
<body>
<%
         response.setContentType("text/html;charset=utf-8");  
         request.setCharacterEncoding("utf-8");           
         String id=(String)request.getParameter("id");  
   
	   	  try{   
	             // 连接到 mongodb 服务
	             MongoClient mongoClient = new MongoClient( "localhost" , 27017 );
	             DB db = mongoClient.getDB( "blog" );  //连接到数据库blog
	             DBCollection coll = db.getCollection("article");  //获取blog数据库中集合user
	            	
	             BasicDBObject query = new BasicDBObject();
	             query.put("_id", new ObjectId(id));
	             BasicDBObject u= new BasicDBObject().append("$inc",new BasicDBObject().append("readNum", 1));
	             coll.update(query, u);
	             response.getWriter().write("true");
	       	     response.getWriter().close();
	          }catch(Exception e){
	       	     response.getWriter().write("false");
	       	     response.getWriter().close();
	             System.err.println( e.getClass().getName() + ": " + e.getMessage() );
	         }    
          
     %>
</body>
</html>